package com.controller;

import com.controller.vo.ResultVO;
import com.dto.RoleApplicationDTO;
import com.entity.RoleApplication;
import com.service.AccountService;
import com.service.RoleApplicationService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: RoleApplicationController
 * Description:
 *
 * @author L_Z_R
 * @version 1.0
 * @create 2025/06/18 16:17
 */
@RestController
public class RoleApplicationController extends BaseController{
     @Autowired
     private RoleApplicationService roleApplicationService;
     @Autowired
     private AccountService accountService;

     @PostMapping("/insertRoleApplication")
     public ResultVO<String> insertRoleApplication(@RequestBody RoleApplication roleApplication){
          roleApplicationService.insertRoleApplication(roleApplication);
          return success();
     }

     @GetMapping("/getAllRoleApplications")
     public ResultVO<List<RoleApplicationDTO>> getAllRoleApplications(){
          return success(roleApplicationService.getAllRoleApplications());
     }

     @PostMapping("/auditRoleApplication")
     @Transactional
     public ResultVO<String> auditRoleApplication(
             @RequestParam("accountId") Integer accountId,
             @RequestParam("status") Byte status,
             @RequestParam(value = "rejectReason",required = false) String rejectReason,
             @RequestParam(value = "accountType",required = false) byte accountType){
          roleApplicationService.auditRoleApplication(accountId, status, rejectReason);
          if (status == 1) {
               accountService.updateAccount(accountId, accountType);
          }
          return success();
     }
}
